﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Work.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class 药品管理 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Drugs",
                columns: table => new
                {
                    DrugId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    DrugName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DrugType = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CostName = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DosageForm = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Specification = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PurchasePrice = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    SellingPrice = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    Inventory = table.Column<int>(type: "int", nullable: false),
                    InventoryUpperLimit = table.Column<int>(type: "int", nullable: false),
                    InventoryLowerLimit = table.Column<int>(type: "int", nullable: false),
                    Efficacy = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreateBy = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UpdateTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    UpdateBy = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Drugs", x => x.DrugId);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "DrugInbounds",
                columns: table => new
                {
                    InboundId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    DrugId = table.Column<int>(type: "int", nullable: false),
                    Quantity = table.Column<int>(type: "int", nullable: false),
                    UnitPrice = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    TotalAmount = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    ProductionDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    ExpirationDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    BatchNumber = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Supplier = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    InboundDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    Operator = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Remarks = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugInbounds", x => x.InboundId);
                    table.ForeignKey(
                        name: "FK_DrugInbounds_Drugs_DrugId",
                        column: x => x.DrugId,
                        principalTable: "Drugs",
                        principalColumn: "DrugId",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "DrugInspections",
                columns: table => new
                {
                    InspectionId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    PrescriptionItemId = table.Column<int>(type: "int", nullable: false),
                    AppointmentId = table.Column<int>(type: "int", nullable: false),
                    PatientId = table.Column<int>(type: "int", nullable: false),
                    RegistrationNum = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PatientName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CardNumber = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DrugId = table.Column<int>(type: "int", nullable: true),
                    DrugName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    InspectionStatus = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    InspectionDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    Inspector = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    InspectionResult = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    HandlingMethod = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsDispensed = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    DispensedDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    Remarks = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugInspections", x => x.InspectionId);
                    table.ForeignKey(
                        name: "FK_DrugInspections_Appintments_AppointmentId",
                        column: x => x.AppointmentId,
                        principalTable: "Appintments",
                        principalColumn: "AppintmentId",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_DrugInspections_Drugs_DrugId",
                        column: x => x.DrugId,
                        principalTable: "Drugs",
                        principalColumn: "DrugId",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_DrugInspections_Patients_PatientId",
                        column: x => x.PatientId,
                        principalTable: "Patients",
                        principalColumn: "PatientId",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_DrugInspections_PrescriptionItems_PrescriptionItemId",
                        column: x => x.PrescriptionItemId,
                        principalTable: "PrescriptionItems",
                        principalColumn: "PrescriptionItemId",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "DrugOutbounds",
                columns: table => new
                {
                    OutboundId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    DrugId = table.Column<int>(type: "int", nullable: false),
                    PrescriptionItemId = table.Column<int>(type: "int", nullable: true),
                    AppointmentId = table.Column<int>(type: "int", nullable: true),
                    PatientId = table.Column<int>(type: "int", nullable: false),
                    CardNumber = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    RegistrationNum = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PatientName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Quantity = table.Column<int>(type: "int", nullable: false),
                    UnitPrice = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    TotalAmount = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    OutboundDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    Operator = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Remarks = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugOutbounds", x => x.OutboundId);
                    table.ForeignKey(
                        name: "FK_DrugOutbounds_Appintments_AppointmentId",
                        column: x => x.AppointmentId,
                        principalTable: "Appintments",
                        principalColumn: "AppintmentId",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_DrugOutbounds_Drugs_DrugId",
                        column: x => x.DrugId,
                        principalTable: "Drugs",
                        principalColumn: "DrugId",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_DrugOutbounds_Patients_PatientId",
                        column: x => x.PatientId,
                        principalTable: "Patients",
                        principalColumn: "PatientId",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_DrugOutbounds_PrescriptionItems_PrescriptionItemId",
                        column: x => x.PrescriptionItemId,
                        principalTable: "PrescriptionItems",
                        principalColumn: "PrescriptionItemId",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_DrugInbounds_DrugId",
                table: "DrugInbounds",
                column: "DrugId");

            migrationBuilder.CreateIndex(
                name: "IX_DrugInbounds_DrugId_InboundDate",
                table: "DrugInbounds",
                columns: new[] { "DrugId", "InboundDate" });

            migrationBuilder.CreateIndex(
                name: "IX_DrugInbounds_InboundDate",
                table: "DrugInbounds",
                column: "InboundDate");

            migrationBuilder.CreateIndex(
                name: "IX_DrugInspections_AppointmentId",
                table: "DrugInspections",
                column: "AppointmentId");

            migrationBuilder.CreateIndex(
                name: "IX_DrugInspections_CreateTime",
                table: "DrugInspections",
                column: "CreateTime");

            migrationBuilder.CreateIndex(
                name: "IX_DrugInspections_DrugId",
                table: "DrugInspections",
                column: "DrugId");

            migrationBuilder.CreateIndex(
                name: "IX_DrugInspections_InspectionStatus",
                table: "DrugInspections",
                column: "InspectionStatus");

            migrationBuilder.CreateIndex(
                name: "IX_DrugInspections_IsDispensed",
                table: "DrugInspections",
                column: "IsDispensed");

            migrationBuilder.CreateIndex(
                name: "IX_DrugInspections_PatientId",
                table: "DrugInspections",
                column: "PatientId");

            migrationBuilder.CreateIndex(
                name: "IX_DrugInspections_PatientId_IsDispensed_CreateTime",
                table: "DrugInspections",
                columns: new[] { "PatientId", "IsDispensed", "CreateTime" });

            migrationBuilder.CreateIndex(
                name: "IX_DrugInspections_PrescriptionItemId",
                table: "DrugInspections",
                column: "PrescriptionItemId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DrugInspections_RegistrationNum",
                table: "DrugInspections",
                column: "RegistrationNum");

            migrationBuilder.CreateIndex(
                name: "IX_DrugOutbounds_AppointmentId",
                table: "DrugOutbounds",
                column: "AppointmentId");

            migrationBuilder.CreateIndex(
                name: "IX_DrugOutbounds_CardNumber",
                table: "DrugOutbounds",
                column: "CardNumber");

            migrationBuilder.CreateIndex(
                name: "IX_DrugOutbounds_DrugId",
                table: "DrugOutbounds",
                column: "DrugId");

            migrationBuilder.CreateIndex(
                name: "IX_DrugOutbounds_DrugId_OutboundDate",
                table: "DrugOutbounds",
                columns: new[] { "DrugId", "OutboundDate" });

            migrationBuilder.CreateIndex(
                name: "IX_DrugOutbounds_OutboundDate",
                table: "DrugOutbounds",
                column: "OutboundDate");

            migrationBuilder.CreateIndex(
                name: "IX_DrugOutbounds_PatientId",
                table: "DrugOutbounds",
                column: "PatientId");

            migrationBuilder.CreateIndex(
                name: "IX_DrugOutbounds_PatientId_OutboundDate",
                table: "DrugOutbounds",
                columns: new[] { "PatientId", "OutboundDate" });

            migrationBuilder.CreateIndex(
                name: "IX_DrugOutbounds_PrescriptionItemId",
                table: "DrugOutbounds",
                column: "PrescriptionItemId");

            migrationBuilder.CreateIndex(
                name: "IX_Drugs_DrugName",
                table: "Drugs",
                column: "DrugName");

            migrationBuilder.CreateIndex(
                name: "IX_Drugs_DrugName_DrugType",
                table: "Drugs",
                columns: new[] { "DrugName", "DrugType" });

            migrationBuilder.CreateIndex(
                name: "IX_Drugs_DrugType",
                table: "Drugs",
                column: "DrugType");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "DrugInbounds");

            migrationBuilder.DropTable(
                name: "DrugInspections");

            migrationBuilder.DropTable(
                name: "DrugOutbounds");

            migrationBuilder.DropTable(
                name: "Drugs");
        }
    }
}
